<?php
	$user = $dataObj->GetUser();
	$blogObj = $dataObj->GetInformation();
	$blogposts = $blogObj->GetBlogposts();
	$paging = $blogObj->GetBlogPages();
	
	if($user != null && $user->GetRank() > 0)
	{
		// Config
		$data = array(
		    "id"	=> "newBlogPostButton",
		    "name"	=> "newBlogPostButton",
		    "type"	=> "submit",
		    "value"	=> "Blogga");
		
		$attributes = array(
		    "name"	=> "newBlogPostForm",
		    "id"	=> "newBlogPostForm");
	    
	    $textarea = array(
		    "id"	=> "message",	    
		    "name"	=> "message",
		    "value"	=> set_value("message"));
	    
	    $headline = array(
		    "id"	=> "headline",
		    "name"	=> "headline",
		    "value" => set_value("headline"));
	    
	    // Print new form , simleys
		echo 
		"<div id='newBlogPost'>".
			form_open(current_url(), $attributes) .
				"<p>" . form_input($headline) . "</p>"
				."<p>". form_textarea($textarea) . "</p>"
				."<p>". form_submit($data) . "</p>" .
			form_close() . "
		</div>" . $blogObj->GetSmileys();	
		
		// Print validation errors
		echo 
		"<div class='validation'>"
			. validation_errors() .
		"</div>";
	}

	
	// Prints the blogposts and counted comments
	foreach($blogposts as $post)
	{
		// Parse smileys
		$message = parse_smileys($post->GetMessage(),base_url().'assets/images/smileys/smileys/');
		
		echo 
		"<div class='blogPost'>
			<p class='detailsHead'>" 
				. "<span class='blogHeadline'>" . $post->GetHeadline() . "</span>"
				. "<span class='blogDate'>" . substr($post->GetPosted(),0,10) .
			"</p>
			<p>"  
				. nl2br($message) . 
		   "</p>
		   <p>
				<a href='".site_url()."/home/comments/".$post->GetBlogId()."'> Comments(".$post->GetComments().") </a>
		   </p>
		</div>";
	}
	
	echo $paging;